feat(telegram): networking isolation and sticky IPv4 fallback#278
Merged
viettranx merged 2 commits intoMar 19, 2026
Merged
Conversation
- Tune MaxIdleConnsPerHost to 64 (default 2 starves concurrent sends) - Fix data race in enableIPv4Only using sync.Once - Add force_ipv4 config option for explicit IPv4-only mode - Narrow auto-detect heuristic to "unreachable" only (avoid false-positive on timeouts) - Use bot username instead of token prefix in logs - Extract applyIPv4Dialer helper for reuse between config and runtime paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses the recent regression in Telegram reliability (intermittent
sendMessagefailures and "Network request failed" logs) by refactoring the networking stack from a shared global dispatcher to a per-account isolated transport model.The Problem
The Telegram networking implementation was previously depending on a shared global dispatcher state for proxy handling, IPv4/IPv6 selection, and DNS order.
When a fallback occurred for one bot, it wasn't effectively retained or isolated. This led to a "cross-contamination" effect where a connectivity failure (like broken IPv6 routing on a VPS) for one account would disrupt all other bot instances, causing them to retry fallback behavior far more often than expected.
The Solution
http.Transport(cloned fromhttp.DefaultTransport). This isolates connection pools, proxies, and dialer settings per bot account.network unreachableortimeout) potentially related to IPv6 routing, it automatically forces its dialer intotcp4mode for all future requests in the current session.